import socket,os
  
server = socket.socket()
server.bind(("192.168.1.100",1000))
server.listen(5)

#数据暂存器
TEMP = [b'H',b'2']

while True:
    conn,addr = server.accept()
    print("Connected to:",addr)
    while True:
        #接收两个字节数据
        data = conn.recv(2)
        #判断接收的字节是否为空，为空则退出
        if not data:
            print("Connected break")
            break
        #将两个字节切片
        info = [data[i:i+1] for i in range(0, len(data), 1)]
        #print(len(info))
        if len(info) == 2 :
            TEMP[0] = info[0]
            TEMP[1] = info[1]
        #字节判断转换输出
        if (TEMP[0] == b'H') :
            print('H',ord(TEMP[1]))
        if (TEMP[0] == b'T') :
            print('T',ord(TEMP[1]))

server.close()